#include "Data.h"
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <iostream>

int main() {
  using namespace boost::interprocess;

  managed_shared_memory segment(open_only, "MySharedMemory");

  Person *p1 = segment.find<Person>("MyPerson").first;
  if (p1) {
    std::cout << "Reader: MyData = (" << p1->age << ", " << p1->height << ", "
              << p1->name << ")" << std::endl;
  }

  std::pair<float, double> *p =
      segment.find<std::pair<float, double>>("MyPair").first;
  if (p) {
    std::cout << "Reader: Pair = (" << p->first << ", " << p->second << ")"
              << std::endl;
  }

  typedef vector<int, allocator<int, managed_shared_memory::segment_manager>>
      MyVector;
  MyVector *my_vector = segment.find<MyVector>("MyVector").first;

  if (my_vector) {
    std::cout << "Reader got: ";
    for (int val : *my_vector)
      std::cout << val << " ";
    std::cout << "\n";
  } else {
    std::cerr << "Vector not found.\n";
  }

  return 0;
}
